package com.medicine.hbp.uitl;

import com.medicine.hbp.R;
import com.medicine.hbp.http.httpUitl;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import android.app.Activity;
import android.text.TextUtils;
import android.widget.Toast;

public class Share {
	private static Activity activity;
	private static String text;
	private static String title;
	private static String url;
	private static String imageUrl;
	private static String ids;
	private static UMImage img;

	/**
	 * 快捷分享
	 *
	 * @param activity
	 * @param text
	 *            文字
	 * @param title
	 *            标题
	 * @param url
	 *            分享的URL
	 * @param imageUrl
	 *            参数图片
	 */
	public static void openShare(Activity activitys, String id,String texts,String titles, String urls, String imageUrls) {
		activity = activitys;
		text = texts;
		title = titles;
		url = urls;
		ids=id;
		if (TextUtils.isEmpty(imageUrls)) {
			img = new UMImage(activity, R.drawable.icon_logo);
		} else {
			img = new UMImage(activity, imageUrls);
		}
		final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[] {
				SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
				SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,
				SHARE_MEDIA.SMS };
		UMWeb web = new UMWeb(url);
		web.setTitle(title);// 标题
		web.setThumb(img); // 缩略图
		web.setDescription(text);// 描述
		new ShareAction(activity).setDisplayList(displaylist)
				.withMedia(web)
				.setCallback(new UMShareListener() {
					@Override
					public void onResult(SHARE_MEDIA arg0) {
						ToastUtil.showShort(activity, "分享成功啦!恭喜您获得10积分");
//						Toast.makeText(activity, " 分享成功啦", Toast.LENGTH_SHORT).show();
						httpUitl.httpSaveShare(ids,title, text, imageUrl==null?"":imageUrl, url,activity);
					}

					@Override
					public void onError(SHARE_MEDIA arg0, Throwable arg1) {
						Toast.makeText(activity, " 分享失败啦", Toast.LENGTH_SHORT)
								.show();
					}

					@Override
					public void onCancel(SHARE_MEDIA arg0) {
						Toast.makeText(activity, " 分享取消了", Toast.LENGTH_SHORT)
								.show();
					}

					@Override
					public void onStart(SHARE_MEDIA arg0) {
						// TODO Auto-generated method stub

					}
				}).open();
		// UMShareAPI shareAPI=UMShareAPI.get(activity);
		// shareAPI.doOauthVerify(activity, SHARE_MEDIA.QQ,authListener);
	}

	/**
	 * 快捷分享
	 *
	 * @param activity
	 * @param text
	 *            文字
	 * @param title
	 *            标题
	 * @param url
	 *            分享的URL
	 * @param imageUrl
	 *            参数图片
	 */
	public static void gxopenShare(Activity activitys, String texts,String titles, String urls) {
		activity = activitys;
		text = texts;
		title = titles;
		url = urls;
		img = new UMImage(activity, R.drawable.icon_logo);
		final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[] {
				SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
				SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,
				SHARE_MEDIA.SMS };
		UMWeb web = new UMWeb(url);
		web.setTitle(title);// 标题
		web.setThumb(img); // 缩略图
		web.setDescription(text);// 描述
		new ShareAction(activity).setDisplayList(displaylist)
				// .withTitle(title)
				// .withTargetUrl(url)
				.withMedia(web)
				.setCallback(new UMShareListener() {
					@Override
					public void onResult(SHARE_MEDIA arg0) {
						ToastUtil.showShort(activity, "关怀发送成功啦!恭喜您获得10积分");
//						Toast.makeText(activity, " 分享成功啦", Toast.LENGTH_SHORT)
//								.show();
						httpUitl.httpgx(text, activity);
					}

					@Override
					public void onError(SHARE_MEDIA arg0, Throwable arg1) {
						Toast.makeText(activity, " 分享失败啦", Toast.LENGTH_SHORT)
								.show();
					}

					@Override
					public void onCancel(SHARE_MEDIA arg0) {
						// Toast.makeText(activity," 分享取消了",
						// Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onStart(SHARE_MEDIA arg0) {
						// TODO Auto-generated method stub

					}
				}).open();
		// UMShareAPI shareAPI=UMShareAPI.get(activity);
		// shareAPI.doOauthVerify(activity, SHARE_MEDIA.QQ,authListener);
	}
	// static UMAuthListener authListener=new UMAuthListener() {
	//
	// public void onError(SHARE_MEDIA arg0, int arg1, Throwable arg2) {
	// ToastUtil.showShort(activity, "onError");
	// httpUitl.httpSaveShare(title, text, imageUrl, url);
	// }
	//
	// public void onComplete(SHARE_MEDIA arg0, int arg1, Map<String, String>
	// arg2) {
	// ToastUtil.showShort(activity, "onComplete");
	// httpUitl.httpSaveShare(title, text, imageUrl, url);
	// }
	//
	// public void onCancel(SHARE_MEDIA arg0, int arg1) {
	// ToastUtil.showShort(activity, "onCancel");
	// httpUitl.httpSaveShare(title, text, imageUrl, url);
	//
	// }
	// };
}
